<script>
xe.lang.msg_empty_search_target = '{$lang->msg_empty_search_target}';
xe.lang.msg_empty_search_keyword = '{$lang->msg_empty_search_keyword}';
</script>
<load target="js/document_admin.js" usecdn="true" />
<div class="x_page-header">
	<h1>{$lang->document} <a class="x_icon-question-sign" href="./admin/help/index.html#UMAN_content_document" target="_blank">{$lang->help}</a></h1>
</div>
<div cond="$XE_VALIDATOR_MESSAGE && $XE_VALIDATOR_ID == 'modules/document/tpl/document_list/1'" class="message {$XE_VALIDATOR_MESSAGE_TYPE}">
	<p>{$XE_VALIDATOR_MESSAGE}</p>
</div>
<form id="fo_list" action="./" method="get">
	<input type="hidden" name="module" value="document" />
	<input type="hidden" name="page" value="{$page}" />
	<table id="documentListTable" class="x_table x_table-striped x_table-hover">
		<caption>
			<a href="{getUrl('', 'module', 'admin', 'act', 'dispDocumentAdminList')}" class="active"|cond="$search_keyword == ''">{$lang->all}<block cond="$search_keyword == ''">({number_format($total_count)})</block></a>
			<i>|</i>
			<a href="{getUrl('search_target', 'is_secret', 'search_keyword', 'N')}" class="active"|cond="$search_target == 'is_secret' && $search_keyword == 'N'">{$status_name_list['PUBLIC']}<block cond="$search_target == 'is_secret' && $search_keyword == 'N'">({number_format($total_count)})</block></a>
			<i>|</i>
			<a href="{getUrl('search_target', 'is_secret', 'search_keyword', 'Y')}" class="active"|cond="$search_target == 'is_secret' && $search_keyword == 'Y'">{$status_name_list['SECRET']}<block cond="$search_target == 'is_secret' && $search_keyword == 'Y'">({number_format($total_count)})</block></a>
			<i>|</i>
			<a href="{getUrl('search_target', 'is_secret', 'search_keyword', 'temp')}" class="active"|cond="$search_target == 'is_secret' && $search_keyword == 'temp'">{$status_name_list['TEMP']}<block cond="$search_target == 'is_secret' && $search_keyword == 'temp'">({number_format($total_count)})</block></a> 
			<a class="x_icon-question-sign" href="./admin/help/index.html#UMAN_faq_temp_document" target="_blank">{$lang->help}</a>
			<i>|</i>
			<a href="{getUrl('', 'module', 'admin', 'act', 'dispDocumentAdminDeclared')}">{$lang->cmd_declared_list}</a>
			<i cond="$search_target == 'ipaddress'">|</i>
			<a href="{getUrl('search_target', 'ipaddress')}" class="active" cond="$search_target == 'ipaddress'">{$lang->ipaddress}:{$search_keyword}({number_format($total_count)})</a>

			<div class="x_btn-group x_pull-right">
				<a href="#manageForm" class="x_btn modalAnchor" data-value="trash">{$lang->trash}</a>
				<a href="#manageForm" class="x_btn modalAnchor" data-value="delete">{$lang->delete}</a>
				<a href="#manageForm" class="x_btn modalAnchor" data-value="move">{$lang->move}</a>
				<a href="#manageForm" class="x_btn modalAnchor" data-value="copy">{$lang->copy}</a>
			</div>
		</caption>
		<thead>
			<tr>
				<th scope="col" class="title">{$lang->title}</th>
				<th scope="col" class="nowr">{$lang->writer}</th>
				<th scope="col" class="nowr">{$lang->readed_count}</th>
				<th scope="col" class="nowr">{$lang->cmd_vote}(+/-)</th>
				<th scope="col" class="nowr">{$lang->date}</th>
				<th scope="col" class="nowr">{$lang->ipaddress}</th>
				<th scope="col" class="nowr">{$lang->status}</th>
				<th scope="col"><input type="checkbox" title="Check All" /></th>
			</tr>
		</thead>
		<tbody>
			<tr loop="$document_list => $no, $oDocument">
				<td class="title"><a href="{getUrl('','document_srl',$oDocument->document_srl)}" target="_blank"><!--@if(trim($oDocument->getTitleText()))-->{htmlspecialchars($oDocument->getTitleText())}<!--@else--><em>{$lang->no_title_document}</em><!--@end--></a></td>
				<td class="nowr"><a href="#popup_menu_area" class="member_{$oDocument->get('member_srl')}">{$oDocument->getNickName()}</a></td>
				<td class="nowr">{$oDocument->get('readed_count')}</td>
				<td class="nowr">{$oDocument->get('voted_count')}/{$oDocument->get('blamed_count')}</td>
				<td class="nowr">{$oDocument->getRegdate("Y-m-d H:i")}</td>
				<td class="nowr"><a href="{getUrl('search_target','ipaddress','search_keyword',$oDocument->get('ipaddress'))}">{$oDocument->get('ipaddress')}</a></td>
				<td class="nowr">{$status_name_list[$oDocument->get('status')]}</td>
				<td><input type="checkbox" name="cart" value="{$oDocument->document_srl}" /></td>
			</tr>
		</tbody>
	</table>
	<div class="x_clearfix">
		<div class="x_btn-group x_pull-right">
			<a href="#manageForm" class="x_btn modalAnchor" data-value="trash">{$lang->trash}</a>
			<a href="#manageForm" class="x_btn modalAnchor" data-value="delete">{$lang->delete}</a>
			<a href="#manageForm" class="x_btn modalAnchor" data-value="move">{$lang->move}</a>
			<a href="#manageForm" class="x_btn modalAnchor" data-value="copy">{$lang->copy}</a>
		</div>
	</div>
</form>
<form action="./" class="x_pagination x_pull-left" style="margin:-36px 0 0 0">
	<input type="hidden" name="error_return_url" value="" />
	<input type="hidden" name="module" value="{$module}" />
	<input type="hidden" name="act" value="{$act}" />
	<input cond="$search_keyword" type="hidden" name="search_keyword" value="{$search_keyword}" />
	<input cond="$search_target" type="hidden" name="search_target" value="{$search_target}" />
	<ul>
		<li class="x_disabled"|cond="!$page || $page == 1"><a href="{getUrl('page', '')}">&laquo; {$lang->first_page}</a></li>
		<block cond="$page_navigation->first_page != 1 && $page_navigation->first_page + $page_navigation->page_count > $page_navigation->last_page - 1 && $page_navigation->page_count != $page_navigation->total_page">
		{@$isGoTo = true}
		<li>
			<a href="#goTo" data-toggle title="{$lang->cmd_go_to_page}">&hellip;</a>
			<span cond="$isGoTo" id="goTo" class="x_input-append">
				<input type="number" min="1" max="{$page_navigation->last_page}" required name="page" title="{$lang->cmd_go_to_page}" />
				<button type="submit" class="x_add-on">Go</button>
			</span>
		</li>
		</block>

		<!--@while($page_no = $page_navigation->getNextPage())-->
		{@$last_page = $page_no}
		<li class="x_active"|cond="$page_no == $page"><a  href="{getUrl('page', $page_no)}">{$page_no}</a></li>
		<!--@end-->

		<block cond="$last_page != $page_navigation->last_page && $last_page + 1 != $page_navigation->last_page">
		{@$isGoTo = true}
		<li>
			<a href="#goTo" data-toggle title="{$lang->cmd_go_to_page}">&hellip;</a>
			<span cond="$isGoTo" id="goTo" class="x_input-append">
				<input type="number" min="1" max="{$page_navigation->last_page}" required name="page" title="{$lang->cmd_go_to_page}" />
				<button type="submit" class="x_add-on">Go</button>
			</span>
		</li>
		</block>
		<li class="x_disabled"|cond="$page == $page_navigation->last_page"><a href="{getUrl('page', $page_navigation->last_page)}" title="{$page_navigation->last_page}">{$lang->last_page} &raquo;</a></li>
	</ul>
</form>
<form action="./" method="get" class="search center x_input-append x_clearfix">
	<input type="hidden" name="module" value="{$module}" />
	<input type="hidden" name="act" value="{$act}" />
	<input type="hidden" name="module_srl" value="{$module_srl}" />
	<input type="hidden" name="error_return_url" value="" />
	<select name="search_target" title="{$lang->search_target}" style="margin-right:4px">
		<!--@foreach($lang->search_target_list as $key => $val)-->
		<option value="{$key}" <!--@if($search_target==$key)-->selected="selected"<!--@end-->>{$val}</option>
		<!--@end-->
	</select>
	<input type="search" name="search_keyword" value="{htmlspecialchars($search_keyword)}" title="{$lang->cmd_search}" />
	<button type="submit" class="x_btn x_btn-inverse">{$lang->cmd_search}</button>
	<a href="{getUrl('','module',$module,'act',$act)}" class="x_btn">{$lang->cmd_cancel}</a>
</form>
<form action="./" method="post" class="x_modal" id="manageForm">
	<input type="hidden" name="module" value="document" />
	<input type="hidden" name="act" value="procDocumentManageCheckedDocument" />
	<input type="hidden" name="type" value="" />
	<input type="hidden" name="module_srl" value="" />
	<input type="hidden" name="success_return_url" value="{getUrl('', 'module', 'admin', 'act', 'dispDocumentAdminList', 'is_secret', $is_secret, 'search_target', $search_target, 'search_keyword', $search_keyword)}" cond="!empty($search_target) && !empty($search_keyword)" />
	<input type="hidden" name="xe_validator_id" value="modules/document/tpl/document_list/1" />
	<div class="x_modal-header">
		<h1>{$lang->document_manager}: <span class="_sub"></span></h1>
	</div>
	<div class="x_modal-body">
		<section class="moveList">
			<table width="100%" id="documentManageListTable" class="x_table x_table-striped x_table-hover">
				<caption><strong>{$lang->selected_document} <span id="selectedDocumentCount"></span></strong></caption>
				<thead>
					<tr>
						<th scope="col" class="title">{$lang->title}</th>
						<th scope="col" class="nowr">{$lang->writer}</th>
						<th scope="col" class="nowr">{$lang->status}</th>
					</tr>
				</thead>
				<tbody>
				</tbody>
			</table>
			<div class="x_control-group" style="padding-right:14px;border-top:0">
				<label for="message">{$lang->message_notice}</label>
				<textarea rows="4" cols="42" name="message_content" id="message" style="width:100%"></textarea>
			</div>
		</section>
		<section class="moveTree" hidden>
			<h1>{$lang->msg_select_menu}</h1>
			<p>{$lang->selected_document_move}</p>
			<div class="tree _menuSelector">
				<select class="site_selector" style="width:100%;display:none"></select><div class="tree" style="height:250px;overflow-y:scroll;border:1px solid #aaa"></div>
			</div>
		</section>
	</div>
	<div class="x_modal-footer">
		<button type="submit" name="type" value="" class="x_btn x_btn-inverse x_pull-right">{$lang->cmd_confirm}</button>
		<!-- value="trash|delete|move|copy" -->
	</div>
</form>
<script>
jQuery(function($){
	// Modal anchor activation
	var $docTable = $('#documentListTable');
	$docTable.find(':checkbox').change(function(){
		var $modalAnchor = $('a[data-value]');
		if($docTable.find('tbody :checked').length == 0){
			$modalAnchor.removeAttr('href').addClass('x_disabled');
		} else {
			$modalAnchor.attr('href','#manageForm').removeClass('x_disabled');
		}
	}).change();
	// Button action
	$('a[data-value]').bind('before-open.mw', function(){
		if($docTable.find('tbody :checked').length == 0){
			$('body').css('overflow','auto');
			alert('{$lang->msg_not_selected_document}');
			return false;
		} else {
			var $this = $(this);
			var $manageForm = $('#manageForm');
			var $modalBody = $manageForm.find('.x_modal-body');
			var thisValue = $this.attr('data-value');
			var thisText = $this.text();
			getDocumentList();
			$manageForm.find('.x_modal-header ._sub').text(thisText).end().find('[type="submit"]').val(thisValue).text(thisText);
			if(thisValue == 'trash' || thisValue == 'delete'){
				$modalBody.removeClass('showTree');
			} else if(thisValue == 'move' || thisValue == 'copy') {
				$.xeShowMenuSelectorIn($('._menuSelector'));
				
				$modalBody.addClass('showTree');
				$tree = $('._menuSelector .tree');
				$tree.bind('select_node.jstree', function(a,b){
					var aSelected = [];
					$tree.find('.jstree-clicked').each(function(idx, el){
						var htParam = $.parseJSON($(this).attr('data-param'));
						aSelected.push({browser_title: htParam.sMenuTitle, mid: htParam.sMenuUrl, module_srl: htParam.sModuleSrl, menu_id: htParam.sMenuId, type: htParam.sType});
						//module_srl
					});

					$('#manageForm input[name=module_srl]').val(aSelected[0].module_srl);
				});
				$('._menuSelector').bind('site_changed', function(){
					$('#manageForm input[name=module_srl]').val('');
				});
			}
		}
	});
});
</script>
